﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class AssetProcedure : ProcedureManager
{
    public override void Init()
    {
        base.Init();
        System.Reflection.Assembly asm = System.Reflection.Assembly.GetAssembly(typeof(AssetCustomAttribute));
        System.Type[] types = asm.GetExportedTypes();

        Func<Attribute[], bool> IsMyAttribute = o =>
        {
            foreach (Attribute a in o)
            {
                if (a is AssetCustomAttribute)
                    return true;
            }

            return false;
        };

        System.Type[] cosType = types.Where(o =>
            {
                return IsMyAttribute(System.Attribute.GetCustomAttributes(o, true));
            }
        ).ToArray();

        
        
        foreach (var VARIABLE in cosType)
        {
            AddProcedure( VARIABLE.Assembly.CreateInstance(VARIABLE.Name) as ProcedureBase);
        }
        
        SetDefaultProcedure(nameof(DownBundleProcedure));

        CreateProceduresFsm();
    }
}
